package com.example.mydb;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        DatabaseManager databaseManager = DatabaseManager.getInstance(this);

        findViewById(R.id.insertData).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 插入数据
                databaseManager.insertData("Alice");
                databaseManager.insertData("Bob");
            }
        });

        findViewById(R.id.queryData).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 查询数据
                List<String> data = databaseManager.queryData();
                for (String name : data) {
                    Log.d("Database", name);
                }
            }
        });

        findViewById(R.id.updateData).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 更新数据
                databaseManager.updateData("Alice", "Alex");
            }
        });

        findViewById(R.id.deleteData).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 删除数据
                databaseManager.deleteData("Bob");
            }
        });
    }
}